package top.jacktgq.itheima.nio.file;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @Author CandyWall
 * @Date 2021/3/19--4:38
 * @Description
 */
public class TestFileChannelTransfer1 {
    public static void main(String[] args) {
        try (
                FileChannel from = new FileInputStream("tmp/data.txt").getChannel();
                FileChannel to = new FileOutputStream("tmp/to.txt").getChannel();
        ) {
            // 复制文件效率高，底层会利用操作系统的零拷贝进行优化，不过每次传输会限制2G文件大小
            from.transferTo(0, from.size(), to);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
